package com.twu.biblioteca;

import java.io.*;
public class ReserveBook {
    public int SearchBook(Book Library[],int n,String Searchvalue) {
      int i;
        for (i=0;i<n;i++){
            if(Searchvalue.equals(Library[i].BookName)==true){
                return i;
            }
        }

        return -1;
    }
    public void Reserve(Book Library[],int n) {
        int Position;
        System.out.println("Enter the book you would like to reserve - ");
        String Search=new String();
        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        try {
            Search=bufferRead.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Position=SearchBook(Library,n,Search);
        if (Position>=0)
        {
            if(Library[Position].CopiesIssued<Library[Position].TotalCopies){
                System.out.println("Thank You!Enjoy the book!");
                Library[Position].CopiesIssued++;
            }
            else if(Library[Position].CopiesIssued==Library[Position].TotalCopies)
                System.out.println("Sorry,we don't have that book yet");
            else System.out.println("Data Error");
        }
        else
        {
            System.out.println("The book cannot be found in our records");
        }

    }
}
